package br.uninove.ic.histogram;

import br.uninove.ic.texture.GrayScaleImage;
import br.uninove.ic.texture.IGrayScaleImage;

public class Histogram {

    
    IGrayScaleImage imgHistogram;
    
    public Histogram(IGrayScaleImage img){
           imgHistogram = img;
    }
    
    
    
    public IGrayScaleImage getImgHistogram(){
    	
    	int maxCount = 0, histogram[] = new int[256];
        for (int row = 0; row < imgHistogram.getHeight(); row++)
            for (int col = 0; col <  imgHistogram.getWidth(); col++)
                if (++histogram[imgHistogram.getPixel(col, row)] > maxCount)
                    maxCount = histogram[imgHistogram.getPixel(col, row)];
        
        final int HEIGHT_MAX_HISTOGRAM = 250;
        imgHistogram = new GrayScaleImage(256, HEIGHT_MAX_HISTOGRAM + 10);
        imgHistogram.initImage(255);
        for (int i = 0; i < 256; i++){
            
            //tracar a linha correspondente para cada nivel de cinza no histograma
            int peak =  (int) (histogram[i] / (double) maxCount * HEIGHT_MAX_HISTOGRAM);
            for(int j=imgHistogram.getHeight()-1; j > imgHistogram.getHeight() - peak; j--){
                imgHistogram.setPixel(i, j, 0);
            }
        }
    	
        return imgHistogram;
    }
    
    
    
    public int peakMaximo(){
        //calcula
        return 0;
    }
    
    //tarefas
    //calcular a media, mediana, minimo e maximo do histograma
    
}
